package com.yhy.server.controller;

import com.yhy.server.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    /**
     * 上报地理信息
     *
     * 接口路径：POST/baidu/location
     *
     * 请求参数: Body:
     *      latitude: 纬度
     *      longitude: 经度
     *      addStr: 位置描述
     *
     * 返回值: 无
     */
    @PostMapping("/location")
    public ResponseEntity location(@RequestBody Map map){
        Double latitude = (Double) map.get("latitude");
        Double longitude = (Double) map.get("longitude");
        System.out.println("latitude=="+latitude);
        System.out.println("longitude=="+longitude);
        Object addStr = map.get("addStr");
        String address = "";
        if(addStr != null) {
            address = (String)addStr;
        }
        return baiduService.saveLocation(latitude,longitude,address);
    }
}
